package converter;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class Converter {
	
	/**
	 * converts a decimal number to a binary number
	 */
	@WebMethod
	public String convertToBinary(long number) {
		return Long.toBinaryString(number);
	}
	
	/**
	 * converts a binary number to a decimal number. returns 0
	 * if binary number is invalid
	 */
	@WebMethod
	public long convertFromBinary(String binary) {
		try {
			return Long.parseLong(binary, 2);
		} catch (NumberFormatException e) {
			throw new IllegalArgumentException("argument is not a valid binary number!");
		}
	}	
}
